package com.ruoyi.project.purchase.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.project.purchase.domain.pojo.OrderBillBean;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.project.purchase.domain.RyOrderBill;
import com.ruoyi.project.purchase.service.IRyOrderBillService;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.framework.web.page.TableDataInfo;

/**
 * 订单关联发票信息Controller
 *
 * @author 萧雪
 * @date 2022-10-25
 */
@RestController
@RequestMapping("/purchase/ryOrderBill")
public class RyOrderBillController extends BaseController
{
    @Autowired
    private IRyOrderBillService ryOrderBillService;

    /**
     * 查询订单关联发票信息列表
     */
    @PreAuthorize("@ss.hasPermi('purchase:ryOrderBill:list')")
    @GetMapping("/list")
    public TableDataInfo list(RyOrderBill ryOrderBill)
    {
        startPage();
        List<RyOrderBill> list = ryOrderBillService.selectRyOrderBillList(ryOrderBill);
        return getDataTable(list);
    }

    /**
     * 导出订单关联发票信息列表
     */
    @PreAuthorize("@ss.hasPermi('purchase:ryOrderBill:export')")
    @Log(title = "订单关联发票信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, RyOrderBill ryOrderBill)
    {
        List<RyOrderBill> list = ryOrderBillService.selectRyOrderBillList(ryOrderBill);
        ExcelUtil<RyOrderBill> util = new ExcelUtil<RyOrderBill>(RyOrderBill.class);
        util.exportExcel(response, list, "订单关联发票信息数据");
    }

    /**
     * 获取订单关联发票信息详细信息
     */
    @PreAuthorize("@ss.hasPermi('purchase:ryOrderBill:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(ryOrderBillService.selectRyOrderBillById(id));
    }

    /**
     * 根据订单id查询关联发票信息
     */
    @GetMapping(value = "/selectByOrderId/{id}")
    public AjaxResult selectRyOrderBillByOrderId(@PathVariable("id") Long id){
        return AjaxResult.success(ryOrderBillService.selectRyOrderBillByOrderId(id));
    }

    /**
     * 新增订单关联发票信息
     */
    @RequestMapping(value = "/addOrderBill")
    public AjaxResult addOrderBill(@RequestBody OrderBillBean orderBillBean){
        return ryOrderBillService.addOrderBill(orderBillBean);
    }


    /**
     * 新增订单关联发票信息
     */
    @PreAuthorize("@ss.hasPermi('purchase:ryOrderBill:add')")
    @Log(title = "订单关联发票信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody RyOrderBill ryOrderBill)
    {
        return toAjax(ryOrderBillService.insertRyOrderBill(ryOrderBill));
    }

    /**
     * 修改订单关联发票信息
     */
    @PreAuthorize("@ss.hasPermi('purchase:ryOrderBill:edit')")
    @Log(title = "订单关联发票信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody RyOrderBill ryOrderBill)
    {
        return toAjax(ryOrderBillService.updateRyOrderBill(ryOrderBill));
    }

    /**
     * 删除订单关联发票信息
     */
    @PreAuthorize("@ss.hasPermi('purchase:ryOrderBill:remove')")
    @Log(title = "订单关联发票信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(ryOrderBillService.deleteRyOrderBillByIds(ids));
    }
}
